package priv.zgh.forum.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import priv.zgh.forum.utils.R;

@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {

    // 使用log4j日志打印
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler
    public R unknownAccount(ForumException e) {
        log.error(e.getMessage(), e);
        R r = R.error();
        r.setCode(e.getCode());
        r.setMessage(e.getMessage());
        return r;
    }
}
